//package com.topisv.tms.jms;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.io.StringWriter;
//import java.io.UnsupportedEncodingException;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.atomic.AtomicInteger;
//
//import javax.jms.Message;
//import javax.jms.MessageListener;
//import javax.xml.bind.JAXB;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.topisv.tms.entity.AreaGroup;
//import com.topisv.tms.entity.EdiOrder;
//import com.topisv.tms.entity.ShopSource;
//import com.topisv.tms.entity.log.OrderLog;
//import com.topisv.tms.entity.work.WorkBatch;
//import com.topisv.tms.entity.work.WorkOrder;
//import com.topisv.tms.jms.vo.MailAreaGroupVo;
//import com.topisv.tms.jms.vo.SendMessage;
//import com.topisv.tms.jms.vo.SendOutMessage;
//import com.topisv.tms.rest.entity.md.request.RouteInfoRequestBody;
//import com.topisv.tms.rest.entity.md.request.TraceDetail;
//import com.topisv.tms.rest.entity.md.request.TransferBody;
//import com.topisv.tms.rest.entity.md.request.TransferData;
//import com.topisv.tms.rest.entity.md.request.TransferSubject;
//import com.topisv.tms.rest.entity.md.request.WarehouseInfoDetail;
//import com.topisv.tms.rest.entity.md.request.WarehouseInfoRequestBody;
//import com.topisv.tms.rest.vo.AreaGroupProVo;
//import com.topisv.tms.rest.vo.CustomerAreaGroupVo;
//import com.topisv.tms.service.AreaGroupService;
//import com.topisv.tms.service.CustomerAreaGroupService;
//import com.topisv.tms.service.LogisticsMailNoService;
//import com.topisv.tms.service.ShopSourceService;
//import com.topisv.tms.service.log.OrderLogService;
//import com.topisv.tms.service.shipped.ShippedBatchService;
//import com.topisv.tms.service.vo.invoice.MDParam;
//import com.topisv.tms.service.work.WorkBatchService;
//import com.topisv.tms.service.work.WorkOrderService;
//import com.topisv.tms.utils.DateUtils;
//import com.topisv.tms.utils.DuXMLDoc;
//import com.topisv.tms.utils.SystemUtil;
//import com.topisv.tms.utils.rfd.MailRFDUtil;
//import com.topisv.tms.utils.vo.HtSendOutVo;
//import com.topisv.tms.utils.vo.MLSSendOutVo;
//
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//
///**
// * 消息接受者
// * @author Administrator
// *
// */
//public class ReceiveMessageListener implements MessageListener{
//	
//    private static final Logger log = LoggerFactory.getLogger(ReceiveMessageListener.class);
//
//    private static String url = MDParam.URL;
//	private static AtomicInteger id = new AtomicInteger(0);
//	@Autowired
//	private ShippedBatchService shippedBatchService;
//	@Autowired
//	private LogisticsMailNoService logisticsMailNoService;
//	@Autowired
//	private SendMessageProducer sendMessageProducer;
//	@Autowired
//	private WorkOrderService  workOrderService;
//	@Autowired
//	private WorkBatchService  workBatchService;
//	@Autowired
//	private CustomerAreaGroupService customerAreaGroupService;
//	@Autowired
//	private AreaGroupService  areaGroupService;
//	@Autowired
//	private ShopSourceService shopSourceService;
//	@Autowired
//	private OrderLogService orderLogService;
//	/**
//	 * MessageListener回调函数.
//	 */
//	@Override
//	public void onMessage(Message m) {
//		try {
//			String type=m.getStringProperty("type");//消息类型
//			String message=m.getStringProperty("message");//消息内容
//		    if("createCustomers_yes".equals(type)){
//				//创建商家
//				log.info("TMS创建商家"+message+"成功");
//			}else if("createBatch_yes".equals(type)){
//				log.info("推送出库批次"+message+"成功");
//				shippedBatchService.saveSendBatchOrderLog(message);
//			}else if("createBatchWMS_yes".equals(type)){
//				log.info("推送WMS出库批次"+message+"成功");
//				WorkBatch workBatch=workBatchService.loadWorkBatchByCode(message);
//				workBatch.setSyncStatus("finish");
//				workBatchService.updateBatch(workBatch);
//			}else if("createYtoNo".equals(type)){
//				log.info("接收申领的运单号"+message+"成功");
//				ObjectMapper objectMapper = new ObjectMapper();
//				MailAreaGroupVo mailAreaGroupVo=objectMapper.readValue(message, MailAreaGroupVo.class);
//				logisticsMailNoService.save(mailAreaGroupVo.getLms());
//				SendMessage sendMessage=new SendMessage();
//				sendMessage.setType("createYtoNo_yes");
//				sendMessage.setMessage("接收成功");
//				sendMessageProducer.sendTopic(sendMessage);
//			}else if("createOrdenoYTO_yes".equals(type)){
//				//接收到创建成功
//				log.info("创建订单成功:"+message);
//				WorkOrder workOrder=this.workOrderService.loadOrderByOrderno(message);
//				workOrder.setEbillStatus("create");
//				this.workOrderService.save(workOrder);
//			}else if("sendOutOrdeno_yes".equals(type)){
//				//返回发货信息
//				ObjectMapper objectMapper = new ObjectMapper();
//				SendOutMessage sendOutMessage=objectMapper.readValue(message, SendOutMessage.class);
//				WorkOrder workOrder=this.workOrderService.loadOrderByOrderno(sendOutMessage.getOrdeno());
//				if (!"finish".equals(workOrder.getSendOutStatus())) {
//					EdiOrder e = workOrder.getOrder();// this.ediOrderService.findByOrdeno(sendOutMessage.getOrdeno());
//					String sendOutStatus = parseSendOutBack(sendOutMessage, e);
//					if (sendOutStatus != null) {
//						workOrderService.updateSendStatusByOrder(sendOutStatus, workOrder.getId());
//					}
//				}
//				
//			}else if("cancelOrdenoYTO_yes".equals(type)){
//				log.info("订单号:"+message+"取消成功");
//			}else if("updateCustomersAreaGroup".equals(type)){
//				log.info("商家覆盖网点更新消息:"+message);
//				Map<String, Class> maps = new HashMap<String, Class>();
//				maps.put("areaGroupProVos", AreaGroupProVo.class);
//				CustomerAreaGroupVo customerAreaGroupVo=(CustomerAreaGroupVo)JSONObject.toBean(JSONObject.fromObject(message), CustomerAreaGroupVo.class, maps);
//				customerAreaGroupService.save(customerAreaGroupVo);
//			}else if("modifyAreaGroup".equals(type)){
//				log.info("网点更新消息:"+message);
//				JSONObject json=JSONObject.fromObject(message);
//				String areaGroupCode=json.getString("groupCode");
//				String groupName=json.getString("groupName");
//				String groupIntro=json.getString("groupIntro");
//				String areas=json.getString("areas");
//		
//				AreaGroup areaGroup=this.areaGroupService.findByGroupCode(areaGroupCode);
//				if(areaGroup==null){
//					areaGroup=new AreaGroup();
//				}
//				areaGroup.setAreas(areas);
//				areaGroup.setGroupName(groupName);
//				areaGroup.setGroupIntro(groupIntro);
//				this.areaGroupService.saveAreaGroup(areaGroup);
//			}else if("createShopSource".equals(type)){
//				log.info("OMS创建店铺的消息:"+message);
//				JSONObject json=JSONObject.fromObject(message);
//				ShopSource shop=new ShopSource();
//				shop.setShopCode(json.getString("shopCode"));
//				shop.setOrdenoSourceCode("oms");
//				shop.setCustomerCode(json.getString("customerCode"));
//				shop.setShopName(json.getString("shopName"));
//				shop.setCreateDate(new Date());
//				shop.setStatus(json.getString("status"));
//				this.shopSourceService.save(shop);
//			}else if("TMSOrdenoLogs".equals(type)){//TMS订单日志消息
//				/* 注释此段代码 2015-07-07 cc
//				 * try {
//					if(null!=message&&!"".equals(message)){
//						JSONObject json=JSONObject.fromObject(message);
//						String ordeno=json.getString("ordeno");
//						String createDate=json.getString("createDate");
//						String operateType=json.getString("operateType");
//						EdiOrder e=this.ediOrderService.findByOrdeno(ordeno);
//						if(e!=null){
//							 log.info("TMS订单日志消息:"+message);
//							 OrderLog ol=new OrderLog();
//							 ol.setAboutInfo(operateType);
//							 ol.setCustomerCode(e.getCustomerCode());
//							 ol.setOperateTime(TimeUtil.getDateMMSS(createDate));
//							 ol.setOperateType("");
//							 ol.setOrderno(ordeno);
//							 this.orderLogService.saveOrderLog(ol);
//							 log.info("TMS订单日志消息保存成功");
//						}
//					}else{
//						 log.info("TMS订单日志消息保存失败");
//					}
//					
//				} catch (Exception e2) {
//					 log.info("TMS订单日志消息保存失败");
//				}*/
//				
//			}
//			else if("warehouseInfo".equals(type)){//TMS订单日志消息
//				
//				try {
//					String[] str = message.split("_");
//					String ordeno=str[0];
//					WorkOrder workOrder = workOrderService.loadByAnyOrderno(ordeno);
//					if(workOrder == null || !"MID".equals(workOrder.getCustomerCode()))
//					{
//						return;
//					}
//					log.info("仓内作业状态回传:"+message);
//					TransferData transferData = new TransferData();
//					TransferSubject transferSubject = new TransferSubject();
//					transferSubject.setSender("PaiUEB");
//					transferSubject.setReceiver("AnntoOMS");
//					transferSubject.setDataGenerationTime(new Date());
//					transferSubject.setTransferFileID(System.nanoTime()+""+getId());
//					transferSubject.setDocumentType("warehouseInfo");
//					transferSubject.setSign("");
//					transferSubject.setVersion("1.0");
//					WarehouseInfoRequestBody warehouseInfoRequestBody = new WarehouseInfoRequestBody();
//					warehouseInfoRequestBody.setCustOrdNo(workOrder.getOrder().getCustomerOrdeno());
//					warehouseInfoRequestBody.setWhCode(workOrder.getOrder().getCusWarehouseCode());
//					warehouseInfoRequestBody.setWhName("");
//					warehouseInfoRequestBody.setCustCustomerCode(workOrder.getOrder().getSubCustomerCode());
//					List<WarehouseInfoDetail> list = new ArrayList<WarehouseInfoDetail>();
//					WarehouseInfoDetail warehouseInfoDetail = new WarehouseInfoDetail();
//					warehouseInfoDetail.setOperationTime(new Date());
//					if("dayin".equals(str[1]))
//					{
//						List<OrderLog> ols = orderLogService.loadLogByOrdernoAndOperateType(ordeno, "9");
//						if(null != ols && !ols.isEmpty())
//						{
//							warehouseInfoDetail.setOperationTime(ols.get(0).getOperateTime());
//						}
//						warehouseInfoDetail.setStepName("打单");
//						warehouseInfoDetail.setOperator("作业员");
//					}
//					else if("jianhuo".equals(str[1]))
//					{
//						List<OrderLog> ols = orderLogService.loadLogByOrdernoAndOperateType(ordeno, "3");
//						if(null != ols && !ols.isEmpty())
//						{
//							warehouseInfoDetail.setOperationTime(ols.get(0).getOperateTime());
//						}
//						warehouseInfoDetail.setStepName("拣货");
//						warehouseInfoDetail.setOperator("作业员");
//					}
//					else if("jiedan".equals(str[1]))
//					{
//						List<OrderLog> ols = orderLogService.loadLogByOrdernoAndOperateType(ordeno, "1");
//						if(null != ols && !ols.isEmpty())
//						{
//							warehouseInfoDetail.setOperationTime(ols.get(0).getOperateTime());
//						}
//						warehouseInfoDetail.setStepName("接单");
//						warehouseInfoDetail.setOperator("系统");
//					}
//					warehouseInfoDetail.setNextStepName("");
//					warehouseInfoDetail.setExpand1(ordeno);
//					warehouseInfoDetail.setNextOperator("");
//					warehouseInfoDetail.setNextOperatorInfo("");
//					warehouseInfoDetail.setExpand2("");
//					warehouseInfoDetail.setExpand3("");
//					warehouseInfoDetail.setExpand4("");
//					warehouseInfoDetail.setExpand5("");
//					warehouseInfoDetail.setOperatorInfo("");
//					
//					list.add(warehouseInfoDetail);
//					warehouseInfoRequestBody.setWarehouseInfoDetails(list);
//					TransferBody transferBody = new TransferBody();
//					transferBody.setContent(warehouseInfoRequestBody);
//					transferData.setTransferBody(transferBody);
//					transferData.setTransferSubject(transferSubject);
//					StringWriter writer = new StringWriter();
//					JAXB.marshal(transferData,writer);
//					//log.info("仓内作业信息回传："+writer.toString());
//					String result = pub(url,writer.toString());
//					//log.info("仓内作业信息回传结果："+result);
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//			else if("kuaidi_sendout".equals(type))
//			{
//				String[] arr = message.split("_");
//				String ordeno=arr[0];
//				WorkOrder workOrder = workOrderService.loadByAnyOrderno(ordeno);
//				if("BJRFD-001".equals(workOrder.getExpressCompany())&&"ebill".equals(workOrder.getBillType()))
//				{
//					String json = MailRFDUtil.confirmOrder(workOrder.getOrder().getOrdeno(),workOrder.getEbillNo());
//					String token = SystemUtil.MD5(json + "|" + MDParam.RFD_KEY);
//					log.info("如风达出库确认:"+MDParam.RFD_URL+"/api/order/OutStore?identity="+ MDParam.RFD_Identity + "&token=" + token);
//					String result = SystemUtil.pub(MDParam.RFD_URL+"/api/order/OutStore?identity="+ MDParam.RFD_Identity + "&token=" + token, json);
//					log.info("如风达出库确认结果:"+result);
//					JSONObject jobj = JSONObject.fromObject(result);
//					if(jobj.getBoolean("IsSuccess"))
//					{
//						workOrder.setEbillStatus("create");
//					}
//				}
//				if(workOrder == null || !"MID".equals(workOrder.getCustomerCode()))
//				{
//					return;
//				}
//				log.info("仓内作业状态回传:"+message);
//				TransferData transferData = new TransferData();
//				TransferSubject transferSubject = new TransferSubject();
//				transferSubject.setSender("PaiUEB");
//				transferSubject.setReceiver("AnntoOMS");
//				transferSubject.setDataGenerationTime(new Date());
//				transferSubject.setTransferFileID(System.nanoTime()+""+getId());
//				transferSubject.setDocumentType("warehouseInfo");
//				transferSubject.setSign("");
//				transferSubject.setVersion("1.0");
//				WarehouseInfoRequestBody warehouseInfoRequestBody = new WarehouseInfoRequestBody();
//				warehouseInfoRequestBody.setCustOrdNo(workOrder.getOrder().getCustomerOrdeno());
//				warehouseInfoRequestBody.setWhCode(workOrder.getOrder().getCusWarehouseCode());
//				warehouseInfoRequestBody.setWhName("");
//				warehouseInfoRequestBody.setCustCustomerCode(workOrder.getOrder().getSubCustomerCode());
//				List<WarehouseInfoDetail> list = new ArrayList<WarehouseInfoDetail>();
//				WarehouseInfoDetail warehouseInfoDetail = new WarehouseInfoDetail();
//				
//				warehouseInfoDetail.setExpand1(ordeno);
//				warehouseInfoDetail.setStepName("发货");
//				warehouseInfoDetail.setOperator("作业员");
//				warehouseInfoDetail.setOperatorInfo("");
//				warehouseInfoDetail.setNextStepName("快递交接");
//				warehouseInfoDetail.setOperationTime(new Date());
//				warehouseInfoDetail.setNextOperator("");
//				warehouseInfoDetail.setNextOperatorInfo("");
//				warehouseInfoDetail.setExpand2("");
//				warehouseInfoDetail.setExpand3("");
//				warehouseInfoDetail.setExpand4("");
//				warehouseInfoDetail.setExpand5("");
//				List<OrderLog> ols = orderLogService.loadLogByOrdernoAndOperateType(ordeno, "5");
//				if(null != ols && !ols.isEmpty())
//				{
//					warehouseInfoDetail.setOperationTime(ols.get(0).getOperateTime());
//				}
//				list.add(warehouseInfoDetail);
//				warehouseInfoRequestBody.setWarehouseInfoDetails(list);
//				TransferBody transferBody = new TransferBody();
//				transferBody.setContent(warehouseInfoRequestBody);
//				transferData.setTransferBody(transferBody);
//				transferData.setTransferSubject(transferSubject);
//				StringWriter writer = new StringWriter();
//				JAXB.marshal(transferData,writer);
//				//log.info("仓内作业信息回传："+writer.toString());
//				String result = pub(url,writer.toString());
//				//log.info("仓内作业信息回传结果："+result);
//			}
//			else if("sendOutOrdeno_mid".equals(type))
//			{
//				String[] arr = message.split("_");
//				String ordeno=arr[0];
//				WorkOrder workOrder = workOrderService.loadByAnyOrderno(ordeno);
//				if(!"MID".equals(workOrder.getCustomerCode()))
//				{
//					return;
//				}
//				log.info("仓内作业状态回传:"+message);
//				TransferData transferData = new TransferData();
//				TransferSubject transferSubject = new TransferSubject();
//				transferSubject.setSender("PaiUEB");
//				transferSubject.setReceiver("AnntoOMS");
//				transferSubject.setDataGenerationTime(new Date());
//				transferSubject.setTransferFileID(System.nanoTime()+""+getId());
//				transferSubject.setDocumentType("warehouseInfo");
//				transferSubject.setSign("");
//				transferSubject.setVersion("1.0");
//				WarehouseInfoRequestBody warehouseInfoRequestBody = new WarehouseInfoRequestBody();
//				warehouseInfoRequestBody.setCustOrdNo(workOrder.getOrder().getCustomerOrdeno());
//				warehouseInfoRequestBody.setWhCode(workOrder.getOrder().getCusWarehouseCode());
//				warehouseInfoRequestBody.setWhName("");
//				warehouseInfoRequestBody.setCustCustomerCode(workOrder.getOrder().getSubCustomerCode());
//				List<WarehouseInfoDetail> list = new ArrayList<WarehouseInfoDetail>();
//				WarehouseInfoDetail warehouseInfoDetail = new WarehouseInfoDetail();
//				warehouseInfoDetail.setExpand1(ordeno);
//				warehouseInfoDetail.setStepName("复核");
//				warehouseInfoDetail.setOperator("作业员");
//				warehouseInfoDetail.setOperatorInfo("");
//				warehouseInfoDetail.setNextStepName("发货");
//				warehouseInfoDetail.setOperationTime(new Date());
//				warehouseInfoDetail.setNextOperator("");
//				warehouseInfoDetail.setNextOperatorInfo("");
//				warehouseInfoDetail.setExpand2("");
//				warehouseInfoDetail.setExpand3("");
//				warehouseInfoDetail.setExpand4("");
//				warehouseInfoDetail.setExpand5("");
//				List<OrderLog> ols = orderLogService.loadLogByOrdernoAndOperateType(ordeno, "4");
//				if(null != ols && !ols.isEmpty())
//				{
//					warehouseInfoDetail.setOperationTime(ols.get(0).getOperateTime());
//				}
//				list.add(warehouseInfoDetail);
//				warehouseInfoRequestBody.setWarehouseInfoDetails(list);
//				TransferBody transferBody = new TransferBody();
//				transferBody.setContent(warehouseInfoRequestBody);
//				transferData.setTransferBody(transferBody);
//				transferData.setTransferSubject(transferSubject);
//				StringWriter writer = new StringWriter();
//				JAXB.marshal(transferData,writer);
//				//log.info("仓内作业信息回传："+writer.toString());
//				String result = pub(url,writer.toString());
//				//log.info("仓内作业信息回传结果："+result);
//			}
//			else if("kuaidi_callback".equals(type))
//			{
//				JSONObject json=null;
//				String status = null;
//				try {
//					json = JSONObject.fromObject(message);
//					status = json.getString("status");
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//				if(null != status && ("polling".equals(status) || "shutdown".equals(status)))
//				{
//					try {
//						JSONObject lastResult = json.getJSONObject("lastResult");
//						String nu = lastResult.getString("nu");
//						WorkOrder workOrder = workOrderService.loadByExpressNo(nu);
//						if(workOrder != null)
//						{
//							if(workOrder == null || !"MID".equals(workOrder.getCustomerCode()))
//							{
//								return;
//							}
//							log.info("路由信息回传:" + nu);
//							TransferData transferData = new TransferData();
//							TransferSubject transferSubject = new TransferSubject();
//							transferSubject.setSender("PaiUEB");
//							transferSubject.setReceiver("AnntoOMS");
//							transferSubject.setDataGenerationTime(new Date());
//							transferSubject.setTransferFileID(System.nanoTime()+""+getId());
//							transferSubject.setDocumentType("routeInfo");
//							transferSubject.setSign("");
//							transferSubject.setVersion("1.0");
//							RouteInfoRequestBody routeInfoRequestBody = new RouteInfoRequestBody();
//							routeInfoRequestBody.setCarrierCode(workOrder.getExpressCompany());
//							routeInfoRequestBody.setCustOrdNo(workOrder.getOrder().getCustomerOrdeno());
//							routeInfoRequestBody.setExpressNo(nu);
//							List<TraceDetail> list = new ArrayList<TraceDetail>();
//							JSONArray data = lastResult.getJSONArray("data");
//							if(data != null && data.size() > 0)
//							{
//								for(int i=data.size()-1; i>=0; i--)
//								{
//									JSONObject jsonObject2 = data.getJSONObject(i); 
//									String time = jsonObject2.getString("ftime");
//									String _status = jsonObject2.getString("status");
//									Date _ftime = DateUtils.getDate(time, "yyyy-MM-dd HH:mm:ss");
//									String context = jsonObject2.getString("context");
//									
//									TraceDetail TraceDetail = new TraceDetail();
//									TraceDetail.setActionDesc(context);
//									TraceDetail.setScanTime(_ftime);
//									TraceDetail.setCity("");
//									TraceDetail.setAction(_status);
//									TraceDetail.setOperationSiteCode("");
//									TraceDetail.setOperationSiteName("");
//									TraceDetail.setOperator("");
//									TraceDetail.setOperatorPhone("");
//									TraceDetail.setOperatorPhone("");
//									TraceDetail.setWeight("");
//									TraceDetail.setQuestionResion("");
//									TraceDetail.setQuestionType("");
//									TraceDetail.setOperationSiteType("");
//									TraceDetail.setSignMan("");
//									TraceDetail.setExpend1("");
//									TraceDetail.setExpend2("");
//									TraceDetail.setExpend3("");
//									TraceDetail.setExpend4("");
//									TraceDetail.setExpend5("");
//									list.add(TraceDetail);
//								}
//								routeInfoRequestBody.setTraceDetails(list);
//								TransferBody transferBody = new TransferBody();
//								transferBody.setContent(routeInfoRequestBody);
//								transferData.setTransferBody(transferBody);
//								transferData.setTransferSubject(transferSubject);
//								StringWriter writer = new StringWriter();
//								JAXB.marshal(transferData,writer);
//								//log.info("路由信息回传："+writer.toString());
//								String result = pub(url,writer.toString());
//								//log.info("路由信息回传结果："+result);
//							}
//						}
//						
//						
//					} catch (Exception e) {
//						log.error("error",e);
//					}
//					
//				
//				}
//			}
//
//		} catch (Exception e) {
//			log.error("接收消息异常", e);
//		}
//	}
//
//	private String parseSendOutBack(SendOutMessage sendOutMessage, EdiOrder e) {
//		String sendOutStatus = null;
//		try {
//			if ("HHQZ".equals(e.getCustomerCode())) {// 美丽说发货
//				JSONObject json = JSONObject.fromObject(sendOutMessage.getParams());
//				MLSSendOutVo mlsSendOutVo = (MLSSendOutVo) JSONObject.toBean(json, MLSSendOutVo.class);
//				log.info("{}", mlsSendOutVo);
//				sendOutStatus = mlsSendOutVo.isState() ? "finish" : "fail";
//			} else if ("fr".equals(e.getErpType())) {
//				String xml = sendOutMessage.getParams();
//				log.info(xml);
//				Map<String, String> map = DuXMLDoc.getResult(xml);
//				String code = map.get("code");
//				sendOutStatus = (null != code && "0".equals(code)) ? "finish" : "fail";
//			} else if ("mls".equals(e.getErpType())) {// 美丽说发货
//				JSONObject json = JSONObject.fromObject(sendOutMessage.getParams());
//				MLSSendOutVo mlsSendOutVo = (MLSSendOutVo) JSONObject.toBean(json, MLSSendOutVo.class);
//				log.info("{}", mlsSendOutVo);
//				sendOutStatus = mlsSendOutVo.isState() ? "finish" : "fail";
//			} else if ("ht".equals(e.getErpType())) {// 禾塘发货
//				JSONObject json = JSONObject.fromObject(sendOutMessage.getParams());
//				HtSendOutVo htSendOutVo = (HtSendOutVo) JSONObject.toBean(json, HtSendOutVo.class);
//				log.info("{}", htSendOutVo);
//				sendOutStatus = ("0".equals(htSendOutVo.getErrorCode())) ? "finish" : "fail";
//			} else if ("oms".equals(e.getErpType())) {// OMS发货
//				JSONObject json = JSONObject.fromObject(sendOutMessage.getParams());
//				String status = json.getString("status");
//				sendOutStatus = ("success".equals(status)) ? "finish" : "fail";
//			} else if ("edb".equals(e.getErpType())) {// E店宝发货
//				String result = sendOutMessage.getParams();
//				log.info("E店宝发货结果:" + result);
//				sendOutStatus = (result != null && result.indexOf("发货成功") >= 0) ? "finish" : "fail";
//			}
//		} catch (Exception e2) {
//			log.error("", e2);
//		}
//		return sendOutStatus;
//	}
//	
//	public static String pub(String serviceURL, String param) {
//		URL url = null;
//		HttpURLConnection connection = null;
//		StringBuffer buffer = new StringBuffer();
//		try {
//			url = new URL(serviceURL);
//			connection = (HttpURLConnection) url.openConnection();
//			connection.setDoOutput(true);
//			connection.setDoInput(true);
//			connection.setUseCaches(false);
//			connection.setRequestMethod("POST");
//			connection.setRequestProperty("Content-Length",param.length()+"");
//			connection.setRequestProperty("Content-Type", "text/xml");
//			// connection.setRequestProperty("User-Agent","Java/1.6.0_29");
//			//connection.connect();
//			String username = "Annto_PaiU";
//	    	String password = "nDsht3^v";
//	    	String input = username + ":" + password; 
//	    	String encoding = getBASE64(input);   
//	    	connection.setRequestProperty( "Authorization","Basic "+encoding); 
//	    	System.out.println(encoding);
//			/*OutputStream os=connection.getOutputStream();
//	        DataOutputStream dos=new DataOutputStream(os);
//	        dos.write(param.getBytes("UTF-8"));
//	        dos.flush();
//	        dos.close(); */
//			OutputStream outputStream = connection.getOutputStream();
//			outputStream.write(param.getBytes("UTF-8"));
//			outputStream.flush();
//			outputStream.close();
//			InputStream inputStream = connection.getInputStream();
//			byte[] bytes = new byte[1024];
//			int count = inputStream.read(bytes);
//			while (count != -1) {
//				buffer.append(new String(bytes, 0, count, "UTF-8"));
//				count = inputStream.read(bytes);
//			}
//			inputStream.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (connection != null) {
//				connection.disconnect();
//			}
//		}
//		return buffer.toString();
//	}
//	public static String getBASE64(String str) {
//	   String s = null;
//	   if (str != null) {
//	    try {
//			s = new sun.misc.BASE64Encoder().encode(str.getBytes("UTF-8"));
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	  }
//	  return s;
//	}
//	private static int getId(){
//		id.compareAndSet(9, 0);
//		return id.incrementAndGet();
//	}
//}
